package net.sk.china.city.controller;

import net.sk.china.city.controller.base.BaseController;
import net.sk.china.city.domain.dto.AjaxResult;
import net.sk.china.city.domain.dto.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import net.sk.china.city.constant.HotActivityOrderKey;
import net.sk.china.city.domain.ArDonate;
import net.sk.china.city.domain.ArTeam;
import net.sk.china.city.domain.dto.PageData;
import net.sk.china.city.domain.dto.WorkHourPageData;
import net.sk.china.city.domain.dto.activity.ActivityInfoDTO;
import net.sk.china.city.domain.dto.analyse.*;
import net.sk.china.city.domain.vo.ArExchangeVO;
import net.sk.china.city.service.IAnalyseService;
import net.sk.china.city.service.IArDonateService;
import net.sk.china.city.service.IArExchangeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "大屏")
@RequiredArgsConstructor
@RestController
@RequestMapping("/data/analyse")
public class AnalyseController extends BaseController {

    private final IAnalyseService analyseService;

    @Autowired
    IArExchangeService arExchangeService;

    @Autowired
    IArDonateService arDonateService;

    @ApiOperation("首页数据统计")
    @GetMapping("/volunteer")
    public AjaxResult volunteer() {
        AnalyseDTO analyseDTO = analyseService.analyseVolunteerData();
        return success(analyseDTO);
    }


//    @ApiOperation("闭包表生成（临时，别乱用）")
//    @GetMapping("/closure")
//    public AjaxResult closure() {
//        analyseService.generateClosure();
//        return success();
//    }

//    @ApiOperation("合并组织架构叶节点，不要动！！")
//    @GetMapping("/mergeLeafNode")
//    public AjaxResult mergeLeafNode() {
//        analyseService.mergeLeafNode();
//        return success();
//    }

    @ApiOperation("社区/村志愿者数量与排行")
    @PostMapping("/site/volunteer/top10")
    public AjaxResult siteVolunteerTop10(@RequestBody VolunteerCountRankSearchDTO volunteerCountRankSearchDTO){
        List<VolunteerCountRankDTO> volunteerCountRankDTO = analyseService.analyseSiteVolunteerTop5(volunteerCountRankSearchDTO);
        return success(volunteerCountRankDTO);
    }

    @ApiOperation("志愿者人群分布趋势")
    @GetMapping("/volunteerPopulation")
    public AjaxResult volunteerPopulation(){
        return success(analyseService.volunteerPopulation());
    }

    @ApiOperation("热门活动统计")
    @GetMapping("/hotActivity")
    public AjaxResult hotActivity(@RequestParam("key") HotActivityOrderKey key){
        List<ActivityRankDTO> activityRankDTOList = analyseService.analyseHotActivity(key);
        return success(activityRankDTOList);
    }

    @ApiOperation("服务站图钉")
    @GetMapping("/site/community/list")
    public AjaxResult siteList(){
        List<SitePin> sitePins = analyseService.siteList();
        return success(sitePins);
    }

    @ApiOperation("服务站下的志愿者列表")
    @GetMapping("/site/community/volunteer/list")
    public AjaxResult serviceSiteVolunteer(Long siteId, int current, int size) {
        PageData<GridVolunteerItem> gridVolunteerItemPageData = analyseService.serviceSiteVolunteer(siteId, current, size);
        return success(gridVolunteerItemPageData);
    }

    @ApiOperation("网格下志愿者列表")
    @GetMapping("/grid/volunteer/list")
    public AjaxResult gridVolunteer(Long gridId, int current, int size) {
        PageData<GridVolunteerItem> volunteerUnderCell = analyseService.getVolunteerUnderCell(gridId, current, size);
        return success(volunteerUnderCell);
    }

    // 原先是点击社区村展示的数据
//    @ApiOperation(value = "服务站弹窗")
//    @GetMapping("/site/community/analysis")
//    public AjaxResult gridAnalysis(@RequestParam Long gridId){
//        GridAnalysis gridAnalysis = analyseService.gridAnalysis(gridId);
//        return success(gridAnalysis);
//    }


//    @ApiOperation("社区/村网格列表（网格选项栏）")
//    @GetMapping("/site/community/grid")
//    public AjaxResult gridPair(@RequestParam Long communityId){
//        List<GridIdNamePair> gridIdNamePairs = analyseService.gridPair(communityId);
//        return success(gridIdNamePairs);
//    }


    // 原先是展示社区村对应网格的志愿者列表，目前是总的志愿者列表了
    @ApiOperation(value = "平台志愿者列表")
    @PostMapping("/site/grid/volunteer")
    public AjaxResult gridVolunteerPage(@RequestBody GridVolunteerPageSearchDTO gridVolunteerPageSearchDTO){
        PageData<GridVolunteerItem> gridVolunteerItems = analyseService.gridVolunteerPage(gridVolunteerPageSearchDTO);
        return success(gridVolunteerItems);
    }

    @ApiOperation(value = "志愿者活动列表")
    @GetMapping("/site/activityList")
    public AjaxResult activityPage(int current, int size) {
        PageData<ActivityInfoDTO> activityInfoDTOPageData = analyseService.activityPage(current, size);
        return success(activityInfoDTOPageData);
    }

    @ApiOperation("志愿者队伍列表")
    @GetMapping("/site/teamList")
    public AjaxResult getTeamList(int current, int size) {
        PageData<ArTeam> teamList = analyseService.getTeamList(current, size);
        return success(teamList);
    }

    @ApiOperation("工时列表")
    @GetMapping("/site/workHourList")
    public AjaxResult getWorkHourData(int current, int size) {
        WorkHourPageData<WorkHourItem> workHourPageData = analyseService.workHourDataPage(current, size);
        return success(workHourPageData);
    }

    @ApiOperation("捐赠排行")
    @GetMapping("/donationRank")
    public AjaxResult donationRank(){
        return success(analyseService.donationRank());
    }

    @ApiOperation("慈善超市销售前五")
    @GetMapping("/SupermarketRank")
    public AjaxResult SupermarketRank(){
        return success(analyseService.SupermarketRank());
    }

    @ApiOperation("报道占比")
    @GetMapping("/ReportProportion")
    public AjaxResult ReportProportion(){
        return success(analyseService.ReportProportion());
    }

    @ApiOperation("慈善超市首页基础数据")
    @GetMapping("/supermarketHome")
    public AjaxResult getSupermarketHome(){
        return success(analyseService.getSupermarketHome());
    }

    @ApiOperation("热门兑换商品列表")
    @GetMapping("/hotExchangeProductList")
    public AjaxResult getHotExchangeProductList() {
        return success(analyseService.getHotExchangeProductList());
    }

    @ApiOperation("获取最新兑换订单")
    @GetMapping("/lastExchange")
    public AjaxResult getLastExchange() {
        return success(analyseService.getLastExchange());
    }

    @ApiOperation("获取捐赠来源占比 个人，企业，组织，政府")
    @GetMapping("/donateSourcePercent")
    public AjaxResult getDonateSourcePercent() {
        return success(analyseService.getDonateSourcePercent());
    }

    @ApiOperation("获取热门商品排行")
    @GetMapping("/popularProductRanking")
    public AjaxResult popularProductRanking() {
        return success(analyseService.popularProductRanking());
    }

    @ApiOperation("义购之家首页基础数据")
    @GetMapping("/homeInfo")
    public AjaxResult getHomeInfo(){
        return success(analyseService.getHomeInfo());
    }

    @ApiOperation("最新订单（义购）")
    @GetMapping("/latestOrders")
    public AjaxResult latestOrders() {
        String orderStatusList = "1";
        return success(analyseService.latestOrders(orderStatusList));
    }

    @ApiOperation("退款订单（义购）")
    @GetMapping("/refundOrder")
    public AjaxResult refundOrder() {
        String orderStatusList = "2";
        return success(analyseService.latestOrders(orderStatusList));
    }

    @ApiOperation("退款订单数量今日本周本月")
    @GetMapping("/refundOrderNums")
    public AjaxResult getRefundOrderNums() {
        return success(analyseService.getRefundOrderNums());
    }

    /**
     * 查询兑换记录列表
     */
    @ApiOperation("兑换记录列表")
    @GetMapping("/exchangeList")
    public TableDataInfo list(Integer pageNumber, Integer pageSize)
    {
        startPage();
        List<ArExchangeVO> list = arExchangeService.selectSimpleArExchangeList();
        return getDataTable(list);
    }

    /**
     * 查询捐赠列表列表
     */
    @ApiOperation("捐赠列表")
    @GetMapping("/donateList")
    public TableDataInfo list(ArDonate arDonate, Integer pageNumber, Integer pageSize)
    {
        startPage();
        return arDonateService.selectArDonateList(arDonate);
    }
}
